var Article = require('../models/article.js');
var rssService = require('../service/blogRssService.js');

exports.blog = function(req, res) {
    Article.createTable(function(err) {
        if (err) {
            console.log(err);
        };
    });
    // first, get blog from db
    Article.fetch(function(dataset, err) {
        if (err) {
            console.log(err);
            res.send(err);
        } else {
            console.log(dataset);
            // then, render page
            res.send("respond with a resource");
        };
    })


    // second, update tiny from rss
    rssService.getBlogs(function(rssResults, err) {
        //console.log(rssResults);
        rssResults.forEach(function(article, err) {
            Article.save(article, function(err) {
                if (err) {
                    console.log(err);
                }
                res.send("respond with a resource");
            });
        });
    });
};